snion中文文档 General setup

通用配置 -Sinon.js

  • Sinon用于创建fakesspiesstubs
  • 默认情况下,它们是在默认沙箱中创建的。 因此我们需要确保在每次测试后还原沙箱。

举个例子,如果您使用的是 Mocha,则可以将还原沙箱的操作放在根目录下的测试文件中:

1
2
3
4
afterEach(() => {
// Restore the default sandbox here
sinon.restore()
})

或者在Jasmine中,您应该将其放在每个描述中:

1
2
3
4
5
6
describe('My test suite', () => {
afterEach(() => {
// Restore the default sandbox here
sinon.restore()
})
})

忘记还原沙箱会导致内存泄漏。
有关使用多个沙箱的更高级设置,请参阅沙箱

Author: liuarui
Link: https://liuarui.github.io/2021/04/26/框架/snion中文文档/General setup/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.